#include <stdlib.h>
#include <gtk/gtk.h>
#include "GTKIPV6_EDITOR.h"

void edit_config_file()
{
    /*
    GtkWidget *win = NULL, *box = NULL;

    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_set_border_width( GTK_CONTAINER(win), 10 );
    gtk_window_set_title( GTK_WINDOW(win), "GTKIPV6_CONFEDITOR_DIRECT" );
    gtk_widget_realize (win);
    g_signal_connect (win, "destroy", G_CALLBACK(gtk_widget_destroy), NULL);

    gtk_widget_show_all(win);
    */

    system("gedit /etc/miredo/miredo.conf");
    return;
}

int main( int argc, char **argv )
{
    GtkWidget *win = NULL;
    GtkWidget *vbox = NULL;
    GtkWidget *label = NULL;
    GtkWidget *combo = NULL;
    GtkWidget *hbox = NULL;
    GtkWidget *hbox2 = NULL;
    GtkWidget *linker = NULL;
    GtkWidget *button = NULL;
    GtkWidget *button2 = NULL;
    GError *err[100];

    gtk_init( &argc, &argv );

    /*
    if( (getuid()) != 0 )
    {
        fprintf( stderr, "You must run it as root!\n");
        exit(-1);
    }
    */

    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_set_border_width( GTK_CONTAINER(win), 10 );
    gtk_window_set_title( GTK_WINDOW(win), "GTKIPV6_CONFEDITOR" );
    gtk_window_set_default_icon_from_file("/usr/share/icons/hicolor/48x48/apps/fedora-logo-icon.png", err);
    gtk_window_set_resizable( GTK_WINDOW(win), FALSE );
    gtk_window_set_deletable( GTK_WINDOW(win), FALSE );
    gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
    gtk_widget_realize (win);
    g_signal_connect (win, "destroy", gtk_main_quit, NULL);

    vbox = gtk_vbox_new( FALSE, 5);
    gtk_container_add( GTK_CONTAINER(win), vbox );

    hbox = gtk_hbox_new( FALSE, 5);
    gtk_container_add( GTK_CONTAINER(vbox), hbox );

    label = gtk_label_new("服务器选择:");
    gtk_label_set_justify( GTK_LABEL(label), GTK_JUSTIFY_LEFT);
    gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0);

    combo = gtk_combo_box_new_text();
    gtk_combo_box_append_text( GTK_COMBO_BOX(combo), "微软Teredo服务器(teredo.ipv6.microsoft.com)");
    gtk_combo_box_append_text( GTK_COMBO_BOX(combo), "teredo.ginzado.ne.jp");
    gtk_combo_box_append_text( GTK_COMBO_BOX(combo), "teredo.iks-jena.de");
    gtk_combo_box_append_text( GTK_COMBO_BOX(combo), "默认测试用服务器(teredo.remlab.net)");
    gtk_combo_box_append_text( GTK_COMBO_BOX(combo), "teredo2.remlab.net");
    gtk_combo_box_set_active( GTK_COMBO_BOX(combo), 3);
    g_signal_connect( GTK_OBJECT(combo), "changed", G_CALLBACK(setserv), NULL);
    gtk_box_pack_start( GTK_BOX(hbox), combo, TRUE, TRUE, 0);

    hbox2 = gtk_hbox_new( FALSE, 5);
    gtk_container_add( GTK_CONTAINER(vbox), hbox2 );

    linker = gtk_button_new_from_stock("手动编辑配置文件");
    //gtk_link_button_set_uri_hook( (GtkLinkButtonUriFunc)edit_config_file, NULL, NULL);
    g_signal_connect( GTK_OBJECT(linker), "clicked", G_CALLBACK(edit_config_file), NULL);
    gtk_box_pack_start( GTK_BOX(hbox2), linker, FALSE, TRUE, 0);

    button = gtk_button_new_from_stock(GTK_STOCK_OK);
    g_signal_connect( GTK_OBJECT(button), "clicked", G_CALLBACK(save_config), NULL);
    gtk_box_pack_end( GTK_BOX(hbox2), button, FALSE, TRUE, 0);

    button2 = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
    g_signal_connect( GTK_OBJECT(button2), "clicked", G_CALLBACK(gtk_main_quit), NULL);
    gtk_box_pack_end( GTK_BOX(hbox2), button2, FALSE, TRUE, 0);

    gtk_widget_show_all(win);
    gtk_main();
    return 0;
}
